package org.projectwithoutname.ui.util;


import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;


public class ScreenToolkit extends Composite {
	
	private Composite parent;
	private Color color;
	
	public ScreenToolkit(Composite parent, int style) {
		super(parent, style);
		this.parent = parent;
	}
	
	public void screenManager(int numColumns, int verticalSpace, boolean columnsEqualWidth){
		
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = numColumns;
		gridLayout.verticalSpacing = verticalSpace;
		gridLayout.makeColumnsEqualWidth = columnsEqualWidth;
		setLayout(gridLayout);
	}
	
	public void setColor(int r, int g, int b){
		color = new Color(getDisplay(), r, g, b);
		this.setBackground(color);
	}
	
	public Color getColor(){
		return color;
	}
	
	public void setParent(){
		parent.setLayout(getLayout());
	}
	
	public GridData size(int width, int height){
		
		GridData gridData = new GridData();
		gridData.heightHint = height;
		gridData.widthHint = width;
		return gridData;
			
	}
	
	public GridData size(int numLines, int width, int height){
		
		GridData gridData = new GridData();
		gridData.heightHint = height;
		gridData.widthHint = width;
		gridData.verticalSpan = numLines;
		return gridData;
			
	}
	
	public GridData sizeAndSpan(int numColumns, int width, int height){
		
		GridData gridData = new GridData();
		gridData = this.size(width, height);
		gridData = this.horizontalSpan(gridData, numColumns);
		return gridData;
	}
	
	public GridData horizontalSpan(GridData gridData, int numColumns){
		gridData.horizontalSpan = numColumns;
		return gridData;
	}
	
	private GridData all(int vertical, int horizontal, int width, int height, int numColumns, int numLines){
		GridData gridData = this.alignment(vertical, horizontal, width, height);
		gridData = this.horizontalSpan(gridData, numColumns);
		gridData.verticalSpan = numLines;
		return gridData;
		
	}
	
	public GridData alignment(int vertical, int horizontal, int width, int height){
		
		GridData gridData = new GridData();
		gridData = this.size(width, height);
		gridData.verticalAlignment = vertical;
		gridData.horizontalAlignment = horizontal;
		gridData.grabExcessHorizontalSpace = true;
		gridData.grabExcessVerticalSpace = true;
		return gridData;
	}
	
	public void putOnScreen(Control objectName, int vertical, int horizontal, int width, int height, int numColumns, int numLines){
		objectName.setLayoutData(this.all(vertical, horizontal, width, height, numColumns, numLines));
	}
	
	public void putOnScreen(Control objectName, int vertical, int horizontal, int width, int height){
		objectName.setLayoutData(this.alignment(vertical, horizontal, width, height));
	}
	
	public void putOnScreen(Control objectName, int width, int height){
		objectName.setLayoutData(this.size(width, height));
	}
	
	public void putOnScreen(Control objectName, int numLines, int width, int height){
		objectName.setLayoutData(this.size(numLines, width, height));
	}
	
	public void putOnScreen(int numColumns, int width, int height, Control objectName){
		objectName.setLayoutData(this.sizeAndSpan(numColumns, width, height));
	}
	
	public void addLine(int numlines, int numColumns){
		for(int i=0; i<numlines; i++){
			Label line = new Label(this, SWT.NONE);
			this.putOnScreen(numColumns, 10, 0, line);
		}
	}
	
	public void addLineSpace(int numlines, int numColumns, int dx){
		for(int i=0; i<numlines; i++){
			Label line = new Label(this, SWT.NONE);
			this.putOnScreen(numColumns, dx, 0, line);
		}
	}
	
	public void addLineXYSpace(int numlines, int numColumns, int dx, int dy){
		for(int i=0; i<numlines; i++){
			Label line = new Label(this, SWT.NONE);
			this.putOnScreen(numColumns, dx, dy, line);
		}
	}
	
	public Composite getComposite(){
		return parent;
	}
	
}
